package com.scf.loanmanage.controller;

import com.scf.loanmanage.dao.CollectionRecordsMapper;
import com.scf.loanmanage.dao.OverDueCollectionMapper;
import com.scf.loanmanage.entity.CollectionRecords;
import com.scf.loanmanage.entity.OverDueCollection;
import com.scf.loanmanage.util.SentSimpleMail;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@RestController
@RequestMapping("/CollectionRecords")
public class CollectionRecordsController {

    @Resource
    OverDueCollectionMapper overDueCollectionMapper;
    @Resource
    CollectionRecordsMapper collectionRecords;

    @GetMapping("/CollectionRecordsIntert")
    public void insert(   String manner, String content, Integer oid) throws Exception {
        System.out.println("time"+content);
        System.out.println("加入的OID是:--"+oid);
        collectionRecords.insert(null, new Date(), manner, content, oid);
        Integer selectcount = collectionRecords.selectcount(oid);
        overDueCollectionMapper.upadte(oid,selectcount);

        SimpleDateFormat s=new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
        Date parse1 = s.parse(new Date().toString());
        String ss=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(parse1);
        SimpleDateFormat sss=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = sss.parse(ss);

        CollectionRecords collectionRecords = this.collectionRecords.selctByid(parse);
        System.out.println("当前时间---"+new Date());
        OverDueCollection overDueCollection = overDueCollectionMapper.selctByid(oid);
        try {
            SentSimpleMail.sendEmail("645805434@qq.com", "jgyqkydqwxodbbai", "亲爱的用户：---"+overDueCollection.getEnterprisename()+"--您好",collectionRecords.getContent(),new String[] {"lr13348869942@163.com"});
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
